<?php
namespace app\admin\model;

use frame\lib\Db;

class Index{
    public static function main()
    {
        $date = date('Y-m-d H:i:s' , time());
        // 用户数量
        $user = User::list();
        $statistics = self::statistics($user);
        // 卡密数量
        $fake = Fake::list();
        // 今日注册
        $todayReg = $statistics['todayReg'];
        // vip用户数量
        $vipUser = $statistics['vipUser'];
        // 今日访问量
        // $statist = Db::name('statistics')->where(['user_id' => $_SESSION['admin']['id']])->find();
        // $heat = $statist['heat'];
        // $log = $statist['log'];
        $data = ['userTotal' => count($user), 'fakeTotal' => count($fake) ,'ip' => ip() , 'todayReg' => $todayReg , 'vipUser' => $vipUser , 'date' => $date ];
        return $data;
    }
    
    public static function statistics($list)
    {
        // 今日注册
        $n = 0;
        // 会员数量
        $m = 0;
        foreach($list as $k => $v)
        {
            if(date('d' , getTime(3,$v['create_time'])) == date('d', time()))
            {
                $n++;
            }
            if(getTime(3 , $v['vip_time']) > time())
            {
                $m++;
            }
        }
        return ['todayReg' => $n , 'vipUser' => $m];
    }
}